

var phantom = require('phantom');

function news() {
  var sitepage, phInstance;
  phantom.create()
    .then(function (instance) {
      phInstance = instance;
      return instance.createPage();
    }).then(function (page) {
      sitepage = page;
      return page.open('https://3g.163.com/touch/news/');
    }).then(function (status) {
      return sitepage.property('content');
    }).then(function (content) {
      var $ = cheerio.load(content);
      $(".recommend-list>article").each(function (i, v) {
        var title = $(v).find('.title').text();
        var href = $(v).find('a').attr('href');
        console.log(title, href);
      });
    }).then(function() {
      sitepage.close();
      phInstance.exit();
    }).catch(function (err) {
      phInstance.exit();
    })
}

//http.createServer(function(){
//    news()
//}).listen(3000);